package com.ilancuo.thread;

/**
 * ThreadLocal内的值改变，不影响外面的值
 */
public class TestThreadLocal {
    public static void main(String[] args) {
        ThreadLocal<Boolean> mBoolThreadLocal = new ThreadLocal<>();
        mBoolThreadLocal.set(true);
        System.out.println("Main thread: " + mBoolThreadLocal.get());

        new Thread("Thread#1") {
            @Override
            public void run() {
                super.run();
                mBoolThreadLocal.set(false);
                System.out.println("Thread#1: " + mBoolThreadLocal.get());
            }
        }.start();

        new Thread("Thread#2") {
            @Override
            public void run() {
                super.run();
                mBoolThreadLocal.set(false);
                System.out.println("Thread#2: " + mBoolThreadLocal.get());
            }
        }.start();

        System.out.println("Main Thread: " + mBoolThreadLocal.get());
    }
}
